package com.rc.saas.tenant.service.sms;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.mapper.sms.TenantSmsRecordMapper;
import com.rc.saas.tenant.model.sms.TenantSmsRecord;
import com.rc.saas.tenant.search.tenant.TenantSmsSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TenantSmsRecordServiceImpl implements TenantSmsRecordService {

    @Autowired
    private TenantSmsRecordMapper tenantSmsRecordMapper;

    @Override
    public TenantSmsRecordMapper getMapper() {
        return tenantSmsRecordMapper;
    }

    @Override
    public PageInfo<TenantSmsRecord> selectBySearch(TenantSmsSearch tenantSmsSearch) {
        PageHelper.startPage(tenantSmsSearch.getOffset(), tenantSmsSearch.getLimit());
        List<TenantSmsRecord> list = tenantSmsRecordMapper.selectBySearch(tenantSmsSearch);
        for (TenantSmsRecord tenantSmsRecord : list) {
            if (tenantSmsRecord.getMemberId() == null) {
                tenantSmsRecord.setMemberName("管理员发送");
            }
        }
        return new PageInfo<TenantSmsRecord>(list);
    }

    @Override
    public List<TenantSmsRecord> exportSmsRecord(TenantSmsSearch tenantSmsSearch) {
        return tenantSmsRecordMapper.exportSmsRecord(tenantSmsSearch);
    }
}
